package com.example.uiclassassignments.Activity;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.uiclassassignments.R;

public class CalendarViewActivity extends AppCompatActivity {

    CalendarView calendarView;
    TextView textView;
    TextView textView2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calendar_view);
        calendarView=findViewById(R.id.calendarView);
        textView=findViewById(R.id.tv1);
        textView2=findViewById(R.id.tv2);
        initView();
    }
    int count=1;
    protected void initView() {
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @SuppressLint("SetTextI18n")
            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
                count++;
                Toast.makeText(CalendarViewActivity.this, year + "年" + month + "月" + dayOfMonth + "日", Toast.LENGTH_LONG).show();
                if (count %2==0) {
                    textView.setText(year + "年" + month + "月" + dayOfMonth + "日");
                    textView2.setText("");
                }else {
                    textView2.setText(year + "年" + month + "月" + dayOfMonth + "日");
                    textView.setText("");
                }
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
}
